function PlotXGlomOutput(voxels,diams,DatasetID,PixelWidth,ThresholdRange)
%% Plot the output of the Xglom pipeline
%
%
%   - Michael Eager,   (michael.eager@monash.edu) 
%   - (c) 2012, Monash Biomedical Imaging, Monash University, Australia

%     Copyright © 2012-2013 Michael Eager <michael.eager@monash.edu> 
%
%     This file is part of Xglom.
% 
%     This is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.

if nargin < 4
 PixelWidth=0.0508;
end
if nargin < 5 
ThresholdRange=1:0.1:15;
end
figure;
subplot(2,1,1);


plot(cumsum(voxels'));xlim([0 1000]); ylim([0 100000])
title(['Xglom --  Glom Size & Diameter Histograms : ' DatasetID],'FontSize',18)
xlabel('Labeled Glomeruli Sizes (num voxels)','FontSize',14)
ylabel('Cumulative Counts','FontSize',14)
annotation('textbox',...
[0.581357142857143 0.633333333333333 0.277571428571429 0.102380952380957],...
    'String',{'Estimated Glomeruli count:', num2str(sum((voxels(19,:)')))},...
    'FitBoxToText','off');
 % imagesc(nimage)
% colormap(flipud(gray));
%axis square;
subplot(2,1,2);


plot(ThresholdRange.*PixelWidth,cumsum((diams')));xlim([0 0.3]); ylim([0 100000])

ylabel('Counts','FontSize',14)
xlabel(['Glomerular Diameter (Pixel width ' num2str(PixelWidth) ')  (mm)'],'FontSize',14)
annotation('textbox',...
     [0.586714285714286 0.142857142857143 0.263285714285714 0.0952380952380958],...
    'String',{'Estimated Glomeruli count:', num2str(sum((diams(19,:)')))},...
    'FitBoxToText','off');
